package com.dm.user.controller;

import com.dm.commons.result.Result;
import com.dm.commons.result.ResultUtil;
import com.dm.user.entity.UserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "用户管理")
@RestController
public class UserController {

    @ApiOperation("获取用户信息")
    @GetMapping("/getUser")
    @PreAuthorize("hasAuthority('p1')")//拥有p1权限方可访问此url
    public Result<UserDTO> getUser(){
        //获取用户身份信息
        UserDTO  userDTO = (UserDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        System.out.println("userDTO = " + userDTO);
        return ResultUtil.success(userDTO);
    }

}
